package org.hxzon.demo.nioserver.apps.echo;

import org.hxzon.nioserver.BufferFactory;
import org.hxzon.nioserver.impl.DumbBufferFactory;
import org.hxzon.nioserver.impl.GenericInputHandlerFactory;
import org.hxzon.nioserver.impl.NioDispatcher;
import org.hxzon.nioserver.impl.StandardAcceptor;

import java.io.IOException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

public class EchoServer {
    private EchoServer() {
        // cannot instantiate
    }

    public static void main(String[] args) throws IOException {
        Executor executor = Executors.newCachedThreadPool();
        BufferFactory bufFactory = new DumbBufferFactory();
        NioDispatcher dispatcher = new NioDispatcher(executor, bufFactory);
        StandardAcceptor acceptor = new StandardAcceptor(Config.port, dispatcher, new GenericInputHandlerFactory(EchoHandler.class));

        dispatcher.start();
        acceptor.newThread();
    }
}
